#include "stoplist.h"
#include <QTextStream>
#include <QMessageBox>

stopList::stopList()
{
}

stopList::stopList(QString path)
{
    loadFile(path);
}

void stopList::loadFile(QString path)
{
    wordList.clear();
    QFile file(path);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.setWindowTitle("Stopword file error");
        msgBox.setText(file.errorString());
        msgBox.exec();
    }
    wordList.clear();
    QTextStream in(&file);
    while (!in.atEnd())
    {
        wordList.append(in.readLine());
    }

    qSort(wordList);
}

bool stopList::isStop(QString word)
{
    return !(qBinaryFind(wordList, word) == wordList.end());
}

